package com.wanxi.controller;

import com.wanxi.model.MessageModel;
import com.wanxi.model.ResultModel;
import com.wanxi.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 杨金乾
 */
@Controller
@CrossOrigin(origins = "*")
public class MessageController {
    @Autowired
    private MessageService messageService;

    @Autowired
    SendMessageController sendMessageController;
    private String table="留言";
    @RequestMapping("/back/message/delete")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel messageDelete(MessageModel model){

        ResultModel resultModel = messageService.delete(model);
        sendMessageController.deleteUserMessages(table);
//        6.返回给前端
        return resultModel;
    }

    @RequestMapping("/back/message/findAll")
    @ResponseBody
    @PreAuthorize("hasAuthority('subPermission') or hasAuthority('allPermission')or hasAuthority('unaccessible')")
    protected ResultModel messageFindAll(MessageModel model) {

        ResultModel resultModel = messageService.findAll(model);
        sendMessageController.findAllUserMessages(table);
//        6.返回给前端
        return resultModel;
    }
}
